home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Other View Systems / MacApp Views / FWMARead.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  20.6 KB  |  667 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMARead.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. // 
  8. //  MacApp view resources reader
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWMAREAD_H
  13. #include "FWMARead.h"
  14. #endif
  15.  
  16. #ifndef FWMAOBJS_H
  17. #include "FWMAObjs.h"
  18. #endif
  19.  
  20. #ifndef FWSVIEW_H
  21. #include "FWSView.h"
  22. #endif
  23.  
  24. #ifndef FWFRAME_H
  25. #include "FWFrame.h"
  26. #endif
  27.  
  28. #ifndef FWFILEOP_H
  29. #include "FWFileOp.h"
  30. #endif
  31.  
  32. #ifndef FWRESOUR_H
  33. #include "FWResour.h"
  34. #endif
  35.  
  36. #ifndef SLFILESY_H
  37. #include "SLFileSy.h"
  38. #endif
  39.  
  40. #ifndef FWMEMHLP_H
  41. #include "FWMemHlp.h"
  42. #endif
  43.  
  44. #ifndef FWMEMMGR_H
  45. #include "FWMemMgr.h"
  46. #endif
  47.  
  48. #include <stdio.h>
  49.  
  50. //========================================================================================
  51. //     Some MacApp Types & Constants
  52. //========================================================================================
  53.  
  54. // template version for MacApp 3.0 views
  55. const short kMAThreeOhTemplateVersion = 0x0300;
  56.  
  57. // UStream.h constants
  58. enum { kNoStandardObject, kStandardObject };
  59.  
  60. enum { kNullObject, kLocalObjectNumber, kClassIDAndClassname, kSignatureAndClassname };
  61.  
  62. enum { kDontForceReplacement, kForceReplacement };
  63.  
  64. typedef long LocalObjectNumber;
  65.  
  66. #pragma options align=mac68k
  67.  
  68. typedef struct MATextStyle {
  69.     Style      tsFace;                    // character Style
  70.     char      filler;                    // tsFace is unpacked byte
  71.     short      tsSize;                    // size in points
  72.     RGBColor tsColor;                    // absolute (RGB) color
  73.     Str255      tsFont;                    // font (family) number
  74. } *MATextStylePtr, **MATextStyleHandle;
  75.  
  76. #pragma options align=reset
  77.  
  78. //========================================================================================
  79. //     FW_CMacAppReader Static Members
  80. //========================================================================================
  81.  
  82. short                        FW_CMacAppReader::gClassCount = 0;
  83. MAClassTableH                FW_CMacAppReader::gTableH = 0;
  84.  
  85. ResType                        FW_CMacAppReader::gDefaultButtonID = 0;
  86. ResType                        FW_CMacAppReader::gCancelButtonID = 0;
  87. FW_CMAScrollBarScroller*    FW_CMacAppReader::gScroller = 0;
  88. FW_CRadioCluster*            FW_CMacAppReader::gCluster = 0;
  89. FW_CPoint                    FW_CMacAppReader::gOffset = FW_kZeroPoint;
  90. FW_CMAClassCollection*        FW_CMacAppReader::gClassCollection = 0;
  91. FW_PFileSpecification*        FW_CMacAppReader::gCurResFileSpec = 0;
  92. FW_Boolean                    FW_CMacAppReader::gUseDebugWarnings = true;
  93.  
  94. //========================================================================================
  95. // runtime information
  96. //========================================================================================
  97.  
  98. FW_DEFINE_AUTO(FW_CMAClassCollection)
  99. FW_DEFINE_AUTO(FW_CMAClassDesc)
  100. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CMAClassDesc)
  101.  
  102. //========================================================================================
  103. //     class FW_CMacAppReader
  104. //========================================================================================
  105.  
  106. #ifdef FW_BUILD_MAC
  107. #pragma segment fwmacapp
  108. #endif
  109.  
  110. // ---------------------------------------------------------------------------
  111. //        FW_CMacAppReader::CreateSubViewsFromMacAppResource
  112. // ---------------------------------------------------------------------------
  113.  
  114. FW_PlatformError FW_CMacAppReader::CreateSubViewsFromMacAppResource(Environment* ev, 
  115.                                                     FW_ResourceID resourceID, 
  116.                                                     FW_CSuperView* superview, 
  117.                                                     FW_MReceiver* receiver,
  118.                                                     EResourceFileKind resFileKind,
  119.                                                     FW_Boolean useDebugWarnings)
  120. {
  121.     FW_PlatformError error = FW_xNoError;
  122.     
  123.     // Reset globales
  124.     gScroller = 0;
  125.     gCluster = 0;
  126.     gOffset = FW_kZeroPoint;
  127.     gDefaultButtonID = 0;
  128.     gCancelButtonID = 0;
  129.     gUseDebugWarnings = useDebugWarnings;
  130.  
  131.     // Pick the right resource file 
  132.     FW_PResourceFile* resFile = GetResFile(ev, resFileKind);
  133.     
  134.     // Try to find the MacApp view resource 
  135.     FW_TRY
  136.     {
  137.         // Create stream from resource.  
  138.         // This will fail is there is no View resource in this file.
  139.         FW_PResource maResource(ev, *resFile, resourceID, FW_kMAType);
  140.         FW_PResourceSink sink(ev, maResource);
  141.         FW_CReadableStream maStream(sink);
  142.         
  143.         // MacApp version is first data in the stream
  144.         short macappVersion;
  145.         maStream >> macappVersion;
  146.         
  147.         if(macappVersion != kMAThreeOhTemplateVersion)
  148.         {
  149.             error = FW_xWrongViewResourceVersion;
  150.         }
  151.         else
  152.         {
  153.             // Read objects and create ODF views
  154.             ReadStreamObject(ev, maStream, superview, receiver, kView);
  155.                     
  156.             // Propagate the PostCreate method to finish creating the views
  157.             PostCreateViewFromStream(ev, superview);
  158.         }
  159.     }
  160.     FW_CATCH_BEGIN
  161.     FW_CATCH_REFERENCE(FW_XException, except)
  162.     {
  163.         error = except.GetPlatformError();
  164.     }
  165.     FW_CATCH_EVERYTHING()
  166.     {
  167.         error = FW_xUnknownError;
  168.     }
  169.     FW_CATCH_END
  170.  
  171.     delete resFile;
  172.     
  173.     return error;    
  174. }
  175.  
  176. // ---------------------------------------------------------------------------
  177. //        FW_CMacAppReader::GetResFile
  178. // ---------------------------------------------------------------------------
  179. // GetResFile returns 0 only when asking for a new resource file and cancelling
  180. // the file dialog.  Otherwise it returns a valid external resource file or 
  181. // the shared library itself.
  182.  
  183. FW_PResourceFile* FW_CMacAppReader::GetResFile(Environment* ev, 
  184.                                                 EResourceFileKind resFileKind)
  185. {
  186.     FW_PResourceFile* resFile = 0;
  187.     OSType maFileTypes[] = {'rsrc', 'RSRC', 'aLib', 'APPL'};        
  188.  
  189.     if (resFileKind == kPartOnly || resFileKind == kPartOrAskUser)
  190.     {
  191.         resFile = FW_NEW(FW_PSharedLibraryResourceFile, (ev));    
  192.     }
  193.     if (resFileKind == kCurrentResFile)
  194.     {
  195.         if (gCurResFileSpec == 0)
  196.         {
  197.             // Try to open the resource file ::sources:<part_name>.rsrc that was used
  198.             // to build the project.
  199.             
  200.             FW_PSharedLibraryResourceFile shLibFile(ev);
  201.             FW_PFileSpecification shLibFileSpec(ev, shLibFile->GetFileSpecification(ev));
  202.             FW_PDirectorySpecification libDir(ev, shLibFileSpec->GetParentDirectory(ev));
  203.             FW_CString libName;
  204.             shLibFileSpec->GetName(ev, libName);
  205.             FW_CString fileName(":Sources:");
  206.             fileName += libName;
  207.             fileName += ".rsrc";
  208.             
  209.             gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, libDir, fileName));
  210.             if (FW_FileSystem_IsValidFile(ev, *gCurResFileSpec) == false)
  211.             {
  212.                 // Else put up the file dialog
  213.                 delete gCurResFileSpec;
  214.                 gCurResFileSpec = 0;
  215.                 FW_OFileSpecification* oSpec = FW_CChooseFile::ChooseFileToOpen(
  216.                                                 FW_COpenFileParameters(4, maFileTypes));
  217.                 if (oSpec != 0)
  218.                     gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, oSpec));
  219.             }
  220.         }
  221.         
  222.         if (gCurResFileSpec != 0)
  223.             resFile = FW_NEW(FW_PResourceFile, (ev, *gCurResFileSpec));
  224.         else
  225.             resFile = FW_NEW(FW_PSharedLibraryResourceFile, (ev));    
  226.     }
  227.     else if (resFileKind == kNewResFile)
  228.     {
  229.         // Ask the user to pick a new file
  230.         FW_OFileSpecification* oSpec = FW_CChooseFile::ChooseFileToOpen(
  231.                                             FW_COpenFileParameters(4, maFileTypes));
  232.         if (oSpec != 0)
  233.         {
  234.             delete gCurResFileSpec;
  235.             gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, oSpec));
  236.         }
  237.         if (gCurResFileSpec != 0)
  238.             resFile = FW_NEW(FW_PResourceFile, (ev, *gCurResFileSpec));
  239.     }
  240.  
  241.     return resFile;
  242. }
  243.  
  244. // ---------------------------------------------------------------------------
  245. //        FW_CMacAppReader::GetResFileName
  246. // ---------------------------------------------------------------------------
  247.  
  248. void FW_CMacAppReader::GetResFileName(Environment* ev, FW_CString& name)
  249. {
  250.     if (gCurResFileSpec != 0)
  251.         (*gCurResFileSpec)->GetName(ev, name);
  252.     else
  253.     {
  254.         FW_PSharedLibraryResourceFile shLibFile(ev);
  255.         FW_PFileSpecification shLibFileSpec(ev, shLibFile->GetFileSpecification(ev));
  256.         shLibFileSpec->GetName(ev, name);
  257.     }
  258. }
  259.         
  260. // ---------------------------------------------------------------------------
  261. //        FW_CMacAppReader::ReadStreamObject
  262. // ---------------------------------------------------------------------------
  263.  
  264. void FW_CMacAppReader::ReadStreamObject(Environment* ev, 
  265.                                         FW_CReadableStream& stream,
  266.                                         FW_CSuperView* superview,
  267.                                         FW_MReceiver* receiver,
  268.                                         ENextObjectType type)
  269. {
  270.     short delimiter;    
  271.     stream >> delimiter;
  272.     
  273.     if (delimiter == kLocalObjectNumber)
  274.     {
  275.         LocalObjectNumber itsObjectNumber;
  276.         stream >> itsObjectNumber;                // ODF ignores this object
  277.     }
  278.     else if (delimiter != kNullObject)
  279.     {
  280.         FW_CMAObject* currentObject = 0;
  281.         if (delimiter == kClassIDAndClassname)
  282.         {
  283.             // Create an uninitialized object. 
  284.             currentObject = ReadObject(ev, stream);        
  285.         }
  286.         else if (delimiter == kSignatureAndClassname)
  287.         {
  288.             // Create an uninitialized object by signature. 
  289.             currentObject = ReadStdObject(ev, stream, type);    
  290.         }
  291.  
  292.         else
  293.         {
  294.             MACAPP_WARNING("FW_CMacAppReader::ReadStreamObject: Unknown delimiter in resource stream");
  295.             FW_Failure(FW_xReadableStream);
  296.         }
  297.     
  298.         if (currentObject)
  299.         {
  300.             currentObject->ReadFrom(ev, stream, superview, receiver);
  301.         }
  302.     }
  303.  
  304. // ---------------------------------------------------------------------------
  305. //        FW_CMacAppReader::ReadStdObject
  306. // ---------------------------------------------------------------------------
  307.  
  308. FW_CMAObject* FW_CMacAppReader::ReadStdObject(Environment* ev, 
  309.                                 FW_CReadableStream& stream, ENextObjectType type)
  310. {
  311.     FW_CMAObject* currentObject = 0;
  312.     ResType classID;
  313.  
  314.     stream >> classID;                    // Read the object's signature. 
  315.  
  316.     long sizePosition = ((FW_ORandomAccessSink *)stream.GetSink())->GetPosition(ev);
  317.     long objectSize, endOfObject;
  318.     stream >> objectSize;
  319.     endOfObject = sizePosition + objectSize;
  320.  
  321.     FW_CString className = ReadStr255(stream);// Read its name. 
  322.  
  323.     // Unlike MacApp we always start to find the class by name first then 
  324.     // we try by class signature (this allows to register all our supported
  325.     // classes by signature only. The user can still register classes by name)
  326.     if (className.IsEmpty() == false)
  327.         currentObject = NewByClassName(className, classID);
  328.     if (currentObject == 0)
  329.         currentObject = NewBySignature(classID);
  330.  
  331.     if (currentObject == 0)
  332.     {
  333.         if (type == kView && classID != kStdScrollerScrollBar)
  334.         {
  335.             // View class wasn't registered. We replace it with a nice pink one!
  336.             // It will display the class name or its signature 
  337.             if (className.IsEmpty())
  338.                 className.ReplaceAll((char*)&classID, 4);
  339.                 
  340.             currentObject = FW_CMAUnknownView::Create(classID, className);    
  341.         
  342.             // Keep the endOfObject position around to skip the data after
  343.             // reading the TView fields
  344.             currentObject->fEndOfObject = endOfObject;    
  345.         }
  346.         else
  347.         {
  348.             // Otherwise we skip over non-view object data here. 
  349.             // WARNING: this may fail when using custom classes! "objectSize" is not
  350.             //            reliable in that case (known MacApp problem)
  351.             ((FW_ORandomAccessSink *)stream.GetSink())->SetPosition(ev, endOfObject);
  352.         }
  353.     }    
  354.  
  355.     return currentObject;
  356. }
  357.  
  358. // ---------------------------------------------------------------------------
  359. //        FW_CMacAppReader::ReadObject
  360. // ---------------------------------------------------------------------------
  361.  
  362. FW_CMAObject* FW_CMacAppReader::ReadObject(Environment* ev, FW_CReadableStream& stream)
  363. {
  364.     long streamID;                                // Class ID in stream. 
  365. //    long currentID;                                // Class ID in program. 
  366.  
  367.     stream >> streamID;                            // Read the object's class ID. 
  368.  
  369.     long sizePosition = ((FW_ORandomAccessSink *)stream.GetSink())->GetPosition(ev);
  370.     long objectSize;
  371.     stream >> objectSize;
  372.  
  373. /**
  374.     FW_CString className = ReadStr255(stream);// Read its name. 
  375.  
  376.     if (className.IsEmpty())        // No class name. Must have seen the class before, 
  377.     {                                // so convert the streamID to the currentID.
  378.         currentID = this->LookupClassID(streamID);
  379.     }
  380.     else
  381.     {                                            // Get ID from name ...
  382.         currentID = ClassDesc::GetClassDescFromClassName(className)->GetClassID();
  383.         this->RegisterClassID(streamID, currentID);// ... and register the IDs. 
  384.     }
  385.  
  386.     data = NULL;
  387.  
  388.     if (currentID == kNilClass)                    // Don't know about the class. 
  389.     {
  390.         // If the streamID is kNilClass then the object was realy
  391.         //    NULL, which is a known object, otherwise the class
  392.         //    isn't available.
  393.         known = streamID == kNilClass;
  394.  
  395.         // Skip over the object's data. 
  396.         this->SetPosition(sizePosition + objectSize);// Skip over its data. 
  397.     }
  398.     else
  399.     {                                            // Create the object. 
  400.         data = (TObject*) ClassDesc::NewByClassID((ClassID) currentID);
  401.         known = TRUE;
  402.     }
  403. **/    
  404.     ((FW_ORandomAccessSink *)stream.GetSink())->SetPosition(ev, sizePosition + objectSize);
  405.     return 0;
  406. }  
  407.  
  408. // ---------------------------------------------------------------------------
  409. //        FW_CMacAppReader::NewBySignature
  410. // ---------------------------------------------------------------------------
  411.  
  412. FW_CMAObject* FW_CMacAppReader::NewBySignature(ResType classID)
  413. {
  414.     FW_CMAObject *theObject = 0;
  415.     short index = FetchClassIndex(classID);
  416.  
  417.     if (index != 0) 
  418.     {
  419.         theObject = (*(*gTableH)[index - 1].creatorFunc)(classID);
  420.     }
  421.     return theObject;
  422. }
  423.  
  424. // ---------------------------------------------------------------------------
  425. //        FW_CMacAppReader::NewByClassName
  426. // ---------------------------------------------------------------------------
  427.  
  428. FW_CMAObject* FW_CMacAppReader::NewByClassName(FW_CString& className, ResType classID)
  429. {
  430.     FW_CMAObject *theObject = 0;
  431.     
  432.     if (gClassCollection)
  433.     {
  434.         FW_TOrderedCollectionIterator<FW_CMAClassDesc> ite(gClassCollection);
  435.         for (FW_CMAClassDesc* classDesc = ite.First(); ite.IsNotComplete(); 
  436.             classDesc = ite.Next())
  437.         {
  438.             if (classDesc->fClassName == className)
  439.             {
  440.                 theObject = classDesc->fClassCreator(classID);
  441.                 break;
  442.             }
  443.         }
  444.     }
  445.     return theObject;
  446. }
  447.  
  448. // ---------------------------------------------------------------------------
  449. //        FW_CMacAppReader::FetchClassIndex
  450. // ---------------------------------------------------------------------------
  451.  
  452. short FW_CMacAppReader::FetchClassIndex(ResType classID)
  453. {
  454.     short        classIndex    = 0;
  455.     MAClassTable    *tableP = *gTableH;
  456.  
  457.     for (short i = 0; i < gClassCount; i++) 
  458.     {
  459.         if (tableP[i].classID == classID) 
  460.         {
  461.             classIndex = i + 1;
  462.             break;
  463.         }
  464.     }
  465.     return classIndex;
  466. }
  467. // ---------------------------------------------------------------------------
  468. //        FW_CMacAppReader::ReadStr255
  469. // ---------------------------------------------------------------------------
  470.  
  471. FW_CString FW_CMacAppReader::ReadStr255(FW_CReadableStream& stream)
  472. {
  473.     char    byteCount;
  474.  
  475.     stream >> byteCount;    
  476.  
  477.     FW_CAcquireTemporarySystemHandle handle(byteCount);
  478.     char* buffer = (char*) handle.GetPointer();
  479.     stream.Read(buffer, byteCount);
  480.     
  481.     return FW_CString(buffer, byteCount);
  482. }
  483.  
  484. // ---------------------------------------------------------------------------
  485. //        FW_CMacAppReader::GetTextStyle
  486. // ---------------------------------------------------------------------------
  487.  
  488. void FW_CMacAppReader::GetTextStyle(short textStyleID, 
  489.                                     FW_CFont& font, 
  490.                                     FW_CColor& color)
  491. {
  492.     MATextStyleHandle textStyleHdl = (MATextStyleHandle) GetResource('TxSt', textStyleID);
  493.     
  494.     if (textStyleHdl == 0)
  495.     {
  496.         if (textStyleID != -1)
  497.         {
  498.             MACAPP_WARNING("MacAppReader Warning: Missing MacApp TxSt resource");
  499.         }
  500.         font = FW_kNormalFont;
  501.         color = FW_kRGBBlack;
  502.     }
  503.     else
  504.     {
  505.         FW_CString fontName;
  506.         fontName.ReplaceAll((*textStyleHdl)->tsFont);
  507.         
  508.         // MacApp text styles use the empty string for the system font and "A"
  509.         // for the application
  510.         if (fontName.IsEmpty())
  511.             fontName = FW_GetSystemFontName();
  512.         else if (fontName == "A")
  513.             fontName = FW_GetDefaultFontName();
  514.         
  515.         // ODF style matches Mac Style enum in Types.h
  516.         FW_FontStyle style = (FW_FontStyle)(*textStyleHdl)->tsFace; 
  517.  
  518.         int size = (*textStyleHdl)->tsSize;
  519.         if (size == 0)
  520.             size = 12;
  521.  
  522.         font = FW_CFont(fontName, style, FW_IntToFixed(size));
  523.         
  524.         color = (*textStyleHdl)->tsColor;
  525.     }
  526. }
  527.  
  528. // ---------------------------------------------------------------------------
  529. //        FW_CMacAppReader::RegisterAllMacAppClasses
  530. // ---------------------------------------------------------------------------
  531. //    Register all MacApp classes supported by ODF
  532.  
  533. void FW_CMacAppReader::RegisterAllMacAppClasses()
  534. {
  535.         FW_CMacAppReader::RegisterSignature(kStdButton,     FW_CMAButton::Create);
  536.         FW_CMacAppReader::RegisterSignature(kStdCheckBox,     FW_CMAButton::Create);
  537.         FW_CMacAppReader::RegisterSignature(kStdCluster,     FW_CMACluster::Create);
  538.         FW_CMacAppReader::RegisterSignature(kStdControl,     FW_CMAControl::Create);
  539.         FW_CMacAppReader::RegisterSignature(kStdDialogView, FW_CMADialog::Create);
  540.         FW_CMacAppReader::RegisterSignature(kStdDialogBehavior, FW_CMADialogBehavior::Create);
  541.         FW_CMacAppReader::RegisterSignature(kStdEditText,     FW_CMAEditText::Create);
  542.         FW_CMacAppReader::RegisterSignature(kStdTEView,     FW_CMATEView::Create);
  543.         FW_CMacAppReader::RegisterSignature(kStdPicture,     FW_CMAPictSView::Create);
  544.         FW_CMacAppReader::RegisterSignature(kStdPopup,         FW_CMAPopupMenu::Create);
  545.         FW_CMacAppReader::RegisterSignature(kStdRadio,         FW_CMAButton::Create);
  546.         FW_CMacAppReader::RegisterSignature(kStdScroller,     FW_CMAScrollBarScroller::Create);
  547.         FW_CMacAppReader::RegisterSignature(kStdStaticText, FW_CMAStaticText::Create);
  548.         FW_CMacAppReader::RegisterSignature(kStdTextGridView, FW_CMATextGridView::Create);
  549.         FW_CMacAppReader::RegisterSignature(kStdTextListView, FW_CMATextGridView::Create);
  550.         FW_CMacAppReader::RegisterSignature(kStdView,         FW_CMAView::Create);
  551.         FW_CMacAppReader::RegisterSignature(kStdWindow,     FW_CMAWindow::Create);
  552.  
  553. #if 0
  554.         MA_REGISTER_SIGNATURE(TIcon, kStdIcon);
  555.         MA_REGISTER_SIGNATURE(TSmallIcon, kStdSmallIcon);
  556.         MA_REGISTER_SIGNATURE(TNumberText, kStdNumberText);
  557.         MA_REGISTER_SIGNATURE(TPattern, kStdPattern);
  558.         MA_REGISTER_SIGNATURE(TTargetBorderView, kStdTargetBorderView);
  559.         MA_REGISTER_SIGNATURE(TDialogTEView, kStdDialogTEView);
  560. #endif
  561. }
  562.  
  563. // ---------------------------------------------------------------------------
  564. //        FW_CMacAppReader::RegisterSignature
  565. // ---------------------------------------------------------------------------
  566.  
  567. void FW_CMacAppReader::RegisterSignature(ResType classID, MAClassCreatorFunc creatorFunc)
  568. {
  569.     short    classIndex = 1;                // One-based index into class table
  570.  
  571.     if (gClassCount == 0) 
  572.     {                
  573.         // Create new class table (ODNewHandle throws kODErrOutOfMemory if it fails)
  574.         gTableH = (MAClassTableH) FW_CMemoryManager::AllocateSystemHandle(sizeof(MAClassTable));
  575.         gClassCount = 1;
  576.                                     
  577.     } 
  578.     else 
  579.     {
  580.         // See if class is already in table
  581.         classIndex = FetchClassIndex(classID);
  582.         
  583.         if (classIndex == 0) 
  584.         {            
  585.             FW_CMemoryManager::ResizeSystemHandle((FW_PlatformHandle) gTableH,
  586.                                         (gClassCount+1) * sizeof(MAClassTable));
  587.             gClassCount++;
  588.             classIndex = gClassCount;
  589.         }
  590.     }
  591.     // Store ID and CreatorFunc
  592.     (*gTableH)[classIndex - 1].classID = classID;
  593.     (*gTableH)[classIndex - 1].creatorFunc = creatorFunc;
  594. }
  595.  
  596. // ---------------------------------------------------------------------------
  597. //        FW_CMacAppReader::RegisterClassName
  598. // ---------------------------------------------------------------------------
  599.  
  600. void FW_CMacAppReader::RegisterClassName(FW_CString& className, MAClassCreatorFunc creatorFunc)
  601. {
  602.     if (gClassCollection == 0)
  603.         gClassCollection = FW_NEW(FW_CMAClassCollection, ());
  604.     
  605.     FW_CMAClassDesc* newClassDesc = FW_NEW(FW_CMAClassDesc, (className, creatorFunc));
  606.     
  607.     FW_TOrderedCollectionIterator<FW_CMAClassDesc> ite(gClassCollection);
  608.     for (FW_CMAClassDesc* classDesc = ite.First(); ite.IsNotComplete(); 
  609.         classDesc = ite.Next())
  610.     {
  611.         if (classDesc->fClassName == newClassDesc->fClassName)
  612.         {
  613.             // Not allowed to register the same class with 2 creators
  614.             FW_ASSERT(classDesc->fClassCreator == newClassDesc->fClassCreator);
  615.             return;
  616.         }
  617.     }
  618.     
  619.     gClassCollection->AddLast(newClassDesc);
  620. }
  621.  
  622. // ---------------------------------------------------------------------------
  623. //        FW_CMacAppReader::ReloadViews
  624. // ---------------------------------------------------------------------------
  625.  
  626. FW_PlatformError FW_CMacAppReader::ReloadViews(Environment* ev, 
  627.                                                 FW_ResourceID resourceID, 
  628.                                                 FW_CFrame* frame, 
  629.                                                 FW_MReceiver* receiver,
  630.                                                 EResourceFileKind resFileKind,
  631.                                                 FW_Boolean useDebugWarnings)
  632. {
  633.     // Delete the whole view hierarchy under the frame 
  634.     frame->DeleteAndResetViews(ev);
  635.     
  636.     // Reload the views from the same resource file
  637.     FW_PlatformError error = CreateSubViewsFromMacAppResource(ev, resourceID, frame, 
  638.                                             receiver, resFileKind, useDebugWarnings);    
  639.     
  640.     frame->Invalidate(ev);
  641.     
  642.     return error;
  643. }
  644.  
  645. // ---------------------------------------------------------------------------
  646. //        FW_CMacAppReader::PostCreateViewFromStream
  647. // ---------------------------------------------------------------------------
  648. // This method is the same as FW_CSuperView::PrivPostCreateViewFromStream which
  649. // cannot be used in ODF 1 because it's private.
  650.         
  651. void FW_CMacAppReader::PostCreateViewFromStream(Environment* ev, FW_CSuperView* view)
  652. {
  653.     // Handle this view first
  654.     view->PostCreateViewFromStream(ev);
  655.     
  656.     // Propagate to its subviews if any
  657.     FW_CViewIterator ite(view);
  658.     for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
  659.     {
  660.         if (subview->HasSubViews(ev))
  661.             PostCreateViewFromStream(ev, (FW_CSuperView *)subview);
  662.         else
  663.             subview->PostCreateViewFromStream(ev);
  664.     }
  665. }
  666.